Skip to content

jj: derive author/committer from git config, not just directory path - #24

Merged
phonkd merged 1 commit into
mainfrom
jj-identity-from-git-config
Jul 13, 2026
Merged

jj: derive author/committer from git config, not just directory path#24
phonkd merged 1 commit into
mainfrom
jj-identity-from-git-config

Conversation

@phonkd

@phonkd phonkd commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary

jj's own config format (checked against the installed 0.43.0's bundled docs, jj help -k config) only supports conditional overrides on repo/workspace path, hostname, or subcommand — there's no equivalent of git's remote-URL-based hasconfig:remote.*.url:*...* condition used in bedag-setup's gitconfig.nix. The path-based --when.repositories scope added in #21 only fixes identity for repos cloned under ~/git/bedag*, and — as surfaced live — doesn't retroactively refresh the committer field on already-created commits, which is what GitLab's push hook actually checks.

This adds a jj zsh function (modules/shell.nix) that shadows the real binary: for any invocation inside a git work tree, it reads git config user.email/user.name (which already resolves correctly per-repo via the existing hasconfig: include) and passes them through as jj --config overrides. That gives jj the same remote-based detection git already has, for both author and committer, on every operation — not just a static path guess. Falls back to jj's own config (including the path-based scope from #21, kept as a fallback for non-colocated jj repos) when not inside a git repo.

Verified in a scratch colocated repo: with the wrapper applied consistently (including to jj git init), both Author and Committer came out correctly from git's resolved identity; a partial test (only wrapping describe, not git init) reproduced the exact stale-author symptom seen live, confirming the mechanism.

Test plan

  • nix-instantiate --parse on modules/shell.nix
  • Manual test in a scratch colocated git+jj repo: wrapped git init/describe/show all report the git-resolved identity for both Author and Committer
  • home-manager switch, open a new shell, run jj show inside ~/git/bedag/observability-deployment and confirm Author/Committer both show the bedag identity without relying on the path scope

…oping

jj's own config format only supports path/hostname/command-based
conditions (--when.repositories etc.) — no remote-URL condition like
git's hasconfig:remote.*.url:. Since colocated repos already resolve
the right identity through git's conditional includes, wrap jj in a
zsh function that reads git config user.name/user.email and passes
them through as --config overrides, so jj mirrors git's remote-based
detection instead of relying on where the repo happens to be cloned.
@phonkd
phonkd marked this pull request as ready for review July 13, 2026 15:10
Copilot AI review requested due to automatic review settings July 13, 2026 15:10
@phonkd
phonkd merged commit b0dfce3 into main Jul 13, 2026
2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a jj wrapper function in the Home Manager Zsh configuration so that, when invoked inside a Git work tree, it derives user.name / user.email from git config and passes them into jj via --config overrides. This aligns JJ’s identity resolution with Git’s existing per-repo identity logic (including remote-URL-based hasconfig: setups), ensuring both Author and Committer are consistently correct on every operation.

Changes:

  • Add a Zsh jj function that detects when it’s running inside a Git work tree.
  • Read git config user.email / user.name and inject them into JJ via --config overrides.
  • Fall back to the real jj binary (and JJ’s own config) when not inside a Git repo or when Git identity is unavailable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread modules/shell.nix
Comment on lines +46 to +52
local email name
email=$(git config user.email 2>/dev/null)
name=$(git config user.name 2>/dev/null)
if [[ -n "$email" && -n "$name" ]]; then
command jj --config "user.email=\"$email\"" --config "user.name=\"$name\"" "$@"
return
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants